package com.hwl.demo21.factory;

import com.hwl.demo21.service.WebSite;
import com.hwl.demo21.service.impl.ConcreteWebSite;

import java.util.Hashtable;

/**
 * 网站工厂
 *
 * @author sentry
 * @since 2023-03-26
 */
public class WebSiteFactory {

    private final Hashtable<String, WebSite> flyweights = new Hashtable<>();

    public WebSite getWebSiteCategory(String key) {
        WebSite webSite = flyweights.get(key);
        if (webSite == null) {
            webSite = new ConcreteWebSite(key);
            flyweights.put(key, webSite);
        }
        return webSite;
    }

    public int getWebSiteCount() {
        return flyweights.size();
    }
}
